#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
verzion=`/usr/bin/sw_vers -productVersion|/usr/bin/sed 's/\.//g'|/usr/bin/cut -c 1,2,3`
#autoexists=`/bin/cat /etc/crontab|grep -ic autohelpmate.txt`
#noexit=0
#if [ $autoexists = $noexit ]; then

#move the cron entries out
/bin/cat /etc/crontab|/usr/bin/sed /start/d > /etc/crontab.tmp

#move the crontab back to where it belongs
/bin/mv /etc/crontab.tmp /etc/crontab

#move the kicker entry out
/bin/cat /etc/crontab|/usr/bin/sed /kicker/d > /etc/crontab.tmp

#move the crontab back to where it belongs
/bin/mv /etc/crontab.tmp /etc/crontab

#add kicker

/bin/echo '*/60		*	*	*	*	root	/etc/auto/kicker.sh' >> /etc/crontab

#fi

if [ $verzion -eq "106" ] ; then

/bin/rm -rf /Library/StartupItems/mhmd/
/bin/rm /Library/LaunchDaemons/com.most.ahm.plist
/bin/launchctl load -w /Library/LaunchDaemons/com.most.sweeper.plist

fi


if [ $verzion -eq "105" ] ; then

/bin/rm -rf /Library/StartupItems/mhmd/
/bin/rm /Library/LaunchDaemons/com.most.ahm.plist
/bin/launchctl load -w /Library/LaunchDaemons/com.most.sweeper.plist

fi


if [ $verzion -eq "104" ] ; then

/bin/rm -rf /Library/StartupItems/mhmd/
/bin/rm /Library/LaunchAgents/com.most.vnc.plist
/bin/rm /Library/LaunchAgents/com.most.vnc.login.plist
/bin/rm /Library/LaunchDaemons/com.most.sweeper.plist

fi


if [ $verzion -lt "104" ]; then

/bin/rm /Library/LaunchDaemons/com.most.ahm.plist
/bin/rm -rf /Library/LaunchDaemons/
/bin/rm -rf /Library/LaunchAgents/

#move the hostconfig entries out

/bin/cat /etc/hostconfig|/usr/bin/sed /MHMD/d > /etc/hostconfig.tmp

#move the hostconfig back to where it belongs

/bin/mv /etc/hostconfig.tmp /etc/hostconfig


/bin/echo 'MHMD=-YES-' >> /etc/hostconfig
/usr/bin/killall mhmd
/sbin/systemstarter start mhmd

fi

#add necessary plist entries

updatestamp=`/bin/date +%s`

/usr/bin/defaults write /Library/Preferences/AutoHelpMate checkInStamp -int $updatestamp
#/usr/bin/defaults write /Library/Preferences/AutoHelpMate AHMClass -int 1


/usr/bin/touch /var/log/autohelpmate.log
/bin/chmod 777 /var/log/autohelpmate.log


exit 0

